from fastapi import APIRouter, Depends, HTTPException
from automaticAI.src.api.dependencies import get_windows_controller
from automaticAI.src.api.models.request.open_app_requestModel import OpenAppRequest
from automaticAI.src.api.models.response.automation_responseModel import AutomationResponse
from automaticAI.src.core.automation.windows_api import WindowsController

router = APIRouter()


@router.post("/open_app", response_model=AutomationResponse)
async def open_app(request: OpenAppRequest,
                   windows_controller: WindowsController = Depends(get_windows_controller)
                   ) -> AutomationResponse:
    """
    打开指定的应用程序。
    :param windows_controller: WindowsController依赖项函数
    :param request: 包含应用程序路径的请求体
    :return: 操作结果
    """
    if windows_controller.open_app(request.app_path):
        return AutomationResponse(status="success", message=f"成功打开应用程序: {request.app_path}")
    else:
        raise HTTPException(status_code=500, detaivl="打开应用程序失败,请检查路径")
